home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 007 (1987-02-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 007 (1987-02-15)(Ossowski, Stefan)(DE)(PD).adf / C Compiler / sieve.c < prev    next >
C/C++ Source or Header  |  1987-03-04  |  464b  |  30 lines

  1.  
  2. #define true 1
  3. #define false 0
  4. #define size 8190
  5. #define sizepl 8191
  6.  
  7. char    flags[sizepl];
  8.  
  9. main() {
  10.     int i,prime,k,count,iter;
  11.     printf("10 iterations\n");
  12.     for(iter=1;iter<= 10;iter++){
  13.         count=0;
  14.         for(i = 0; i<=size;i++)
  15.             flags[i]=true;
  16.         for(i=0;i <= size; i++){
  17.             if(flags[i]){
  18.                 prime = i+i+3;
  19.                 k=i+prime;
  20.                     while(k<=size){
  21.                         flags[k] = false;
  22.                         k += prime;
  23.                         }
  24.                     count = count+1;
  25.                 }
  26.             }
  27.         }
  28.     printf("\n%d primes\n",count);
  29.     }
  30.